package com.bdqn.boot.yuanshen.controller;

import com.bdqn.boot.yuanshen.bean.UserBehavior;
import com.bdqn.boot.yuanshen.service.UserBehaviorService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class UserBehaviorController {

    @Autowired
    private UserBehaviorService userBehaviorService;

    // 根据用户ID查询行为记录
    @GetMapping("/Behavior/{userId}")
    public PageInfo<UserBehavior> getByUserId(@PathVariable Integer userId,
                                          @RequestParam(defaultValue = "1") int pageNum,
                                          @RequestParam(defaultValue = "10") int pageSize) {
        return userBehaviorService.getUserBehaviorByUserId(userId, pageNum, pageSize);
    }

    // 根据视频ID查询行为记录
    @GetMapping("/Behavior/video/{videoId}")
    public PageInfo<UserBehavior> getByVideoId(@PathVariable Integer videoId,
                                           @RequestParam(defaultValue = "1") int pageNum,
                                           @RequestParam(defaultValue = "10") int pageSize) {
        return userBehaviorService.getUserBehaviorByVideoId(videoId, pageNum, pageSize);
    }

    // 添加用户行为记录
    @PostMapping("/add")
    public String addUserBehavior(@RequestBody UserBehavior userBehavior) {
        userBehaviorService.addUserBehavior(userBehavior);
        return "success";
    }

    @GetMapping("/Behavior")
    public PageInfo<UserBehavior>getBehavior(@RequestParam(defaultValue = "1") int pageNum,
                                             @RequestParam(defaultValue = "10") int pageSize){
        return userBehaviorService.getAllUserBehaviors(pageNum, pageSize);
    }


}